<?php
/* 
 * 
 * 
 */
class OrderController extends Controller
{

     public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function accessRules() {
        return array(
			array('deny',
				'actions' => array('Getorder'),
				'users'=>array('?'),
			),
		);
    }

    public function actionGetorder()
    {
        $order = new OrderForm;
        if(isset($_POST['OrderForm']))
        { 
            foreach($_POST['OrderForm'] as $name=>$value)
            {

                    $order->$name=$value;
            }
             $user= new User();
            $order_save=new order();
            echo $order->type;
            $order_save->id_type=$order->type;
            $order_save->subjekt=$order->subjekt_s;
            $order_save->date=date('Y-m-d');
            $order_save->cost=$order->cost;
            $order_save->vol_start=$order->vol_start;
            $order_save->vol_end=$order->vol_end;
            $order_save->text=$order->text;
            $order_save->srok=$order->srok;
            $order_save->name=$order->name;
            $order_save->user_id=Yii::app()->user->getId();

            $user=user::model()->findByPk(Yii::app()->user->getId());
            $count_zak=$user->user_info->zak;
            $user->user_info->zak=$count_zak+1;
            $user->user_info->save();

            $order_save->save();

        }
            $typ = type::model()->findAll(
                     array('order' => 'type_name'));

        // при помощи listData создаем массив вида $ключ=>$значение
                $list = CHtml::listData($typ,
                    'id_type', 'type_name');
       
         $this->render('order',array('list'=>$list,'order'=>$order));
    }

    function save($param)
    {

    }
    function actionList()
    {
        if (($_POST['subjekt']!='')|($_POST['id_type']!='')|($_POST['name']!=''))
        {
            $order = order::model()->findAll('subjekt=:subjekt OR id_type=:id_type OR name=:name',array(':subjekt'=>$_POST['subjekt'],':id_type'=>$_POST['id_type'],':name'=>$_POST['name']));
		$this->render('orderlist',array('order'=>$order));
        }
         else
         {
             $order = order::model()->findAll();
		$this->render('orderlist',array('order'=>$order));
         }


         
    }

    function actionOrderpage()
    {
        if(isset($_GET['id']))
        {
            $order=order::model()->findByPk($_GET['id']);
            $this->render('orderpage',array('order'=>$order));

        }
    }
    function actionFind()
    {

        $this->render('find');
    }

}
?>
